const api = require("../../../utils/api")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: ['01', '02', '03', '04', '05', '06']
  },
  choise(e) {
    this.setData({
      num: e.currentTarget.dataset.index
    })
  },
  getmh() {
    this.setData({
      getmh: 1
    })
  },
  shake() {
    const _ = this;
    wx.request({
      url: 'https://zg99.offcn.com/index/choujiang/getcjusers?actid=51661&callback=?',
      data: {
        phone: wx.getStorageSync('51661phone'),
        sstimes: Date.parse(new Date())
      },
      success: res => {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }

        if (theJson.lists != undefined) {
          const times = theJson.lists.length
          const ifShare = wx.getStorageSync('ifShare')
          if (times >= 2) {
            api.showToastNone('您已经抽过两次盲盒了！')
          } else if (times == 1 && ifShare != 1) {
            api.showToastNone('请分享好友获取机会！')
          } else if (times == 1 && ifShare == 1) {
            this.setData({
              shake: 1
            })
            setTimeout(function () {
              _.lotter()
            }, 2000)
          }
        } else {
          this.setData({
            shake: 1
          })

          setTimeout(function () {
            _.lotter()
          }, 2000)
        }

      }
    })


  },

  lotter() {
    const _ = this;
    wx.request({
      url: 'https://zg99.offcn.com/index/choujiang/lottery?actid=51661&callback=?',
      data: {
        phone: wx.getStorageSync('51661phone'),
        isagree: true,
        sstimes: Date.parse(new Date())
      },
      success: res => {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        _.setData({
          jp: theJson,
          zj: 1,
          getmh: !1
        })

      }
    })
  },
  jp() {
    const _ = this;
    wx.request({
      url: 'https://zg99.offcn.com/index/choujiang/getcjusers?actid=51661&callback=?',
      data: {
        phone: wx.getStorageSync('51661phone'),
        sstimes: Date.parse(new Date())
      },
      success: res => {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson.lists)
        _.setData({
          jp: theJson,
          my: 1,
          zj: !1,
          getmh: !1,
          mylists: theJson.lists
        })

      }
    })
  },
  copy: function (e) {
    const _ = this;
    wx.setClipboardData({
      data: _.data.link,
      success: function (res) {
        wx.showToast({
          title: '复制成功'
        })
      }
    })
  },

  getmyprize(e) {
    const {
      prizeid
    } = e.currentTarget.dataset
    console.log(prizeid)
    if (prizeid == 1) {
      this.setData({
        getname: '线上卫生课程优惠券1000',
        ewm: 1,
        my: !1
      })
    } else if (prizeid == 2) {
      this.setData({
        getname: '线上卫生课程优惠券500',
        ewm: 1,
        my: !1
      })
    } else if (prizeid == 3) {
      this.setData({
        getname: '线上卫生课程优惠券300',
        ewm: 1,
        my: !1
      })
    } else if (prizeid == 4) {
      this.setData({
        getname: '价值149元《笔试智学班》系列课程',
        link: 'http://sdzhonggong.mikecrm.com/DI6YjFq',
        lq: 1,
        my: !1
      })
    } else if (prizeid == 5) {
      this.setData({
        getname: '《精选思维导图+易混易错点》含七大专业加公基电子版资料',
        link: 'https://www.wsexam.com/2022/jzhd_1130/72094.html',
        lq: 1,
        my: !1
      })
    } else {
      this.setData({
        getname: '备考刷题包《精选3000题》含五大专业加公基电子版资料',
        link: 'https://www.wsexam.com/2022/jzhd_1130/72082.html',
        lq: 1,
        my: !1
      })
    }
  },
  close() {
    this.setData({
      my: !1,
      lq: !1,
      ewm: !1,
      zj: !1,
      getmh: !1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  onShareAppMessage() {
    const _ = this;
    setTimeout(function () {
      _.setData({
        zj: !1
      })
    }, 2000)
    wx.setStorageSync('ifShare', '1')
    let area = wx.getStorageSync('area')
    let agent = wx.getStorageSync('agent')
    let page = wx.getStorageSync('page')
    return {
      title: '2023山东卫生考试幸运盲盒机',
      path: '/pages/mh/login/login?area=' + area + '&agent=' + agent + '&page=' + page // 路径，传递参数到指定页面。
    }
  }
})